{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "【乐学偶得】【Python进阶之路】之【LBYL与EAFP】\n",
    "乐学偶得版权所有  主讲人：William LX_LAB教研团队提供技术支持 \n",
    "公众号：乐学Fintech 网易云课堂：乐学偶得"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "LBYL (Look Before You Leap):\n",
    "看看再跃\n",
    "并不是“信仰之跃”，你去“跃”的时候，要看看：\n",
    "\n",
    "EAFP(It's Easier to Ask Forgiveness than Permission)\n",
    "通常情况下，我们要求准许不如要求原谅来的容易（先斩后奏！）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# LBYL \n",
    "def divide_LBYL(x,y):\n",
    "    if y == 0 :\n",
    "        print(\"Error! You have attempt to divide by 0!!!! Which is not possible in math.\")\n",
    "    else:\n",
    "        return x/y\n",
    "divide_LBYL(10,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#EAFP\n",
    "def divide_EAFP(x,y):\n",
    "    try:\n",
    "        return x/y\n",
    "    except ZeroDivisionError:\n",
    "        print(\"Error! You have attempt to divide by 0!!!! Which is not possible in math.\")\n",
    "        return None\n",
    "divide_EAFP(10,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
